//
//  MessageCenterCell.m
//  carcareIOS
//
//  Created by 王然 on 16/8/31.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MessageCenterCell.h"
#define CELL_HEIGHT (77)

#define Label_Color (COLOR_HEXSTRING(@"#191919"))
#define Label_Detail_Color (COLOR_HEXSTRING(@"#696969"))
#define Label_Gray_Color (COLOR_HEXSTRING(@"#bbbbbb"))

@interface MessageCenterCell()

@property (nonatomic , strong) UIImageView * iconImageV;

@property (nonatomic , strong) UILabel * titleL;

@property (nonatomic , strong) UILabel * grayTitleL;//标题右侧时间label

@property (nonatomic , strong) UILabel * detailL;


@end
@implementation MessageCenterCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}
- (void)createUI
{
    CGFloat iconX = 13 * __MAIN_RATIO_375;
    UIImage * icon = ImageNamed(@"carMessageIcon");
    CGFloat iconImageVW = 50 * __MAIN_RATIO_375 ;
    CGFloat iconImageVH = iconImageVW * icon.size.height / icon.size.width;
    self.iconImageV = [[UIImageView imageViewWithFrame:CGRectMake(iconX, (CELL_HEIGHT - iconImageVH) / 2, iconImageVW, iconImageVH) image:icon] setupOnView:self];
    
    CGFloat titleLX = self.iconImageV.right + 12 * __MAIN_RATIO_375;
    CGFloat grayTitleLW = 95;
    CGFloat detailLW = __MAIN_WIDTH - titleLX - iconX * 2;
    CGFloat titleLW = detailLW - grayTitleLW + iconX;
    CGFloat titleLY = 13;
    CGFloat titleLH = 21;
    self.titleL = [[UILabel labelWithFrame:CGRectMake(titleLX, titleLY, titleLW, titleLH) font:FONT_DEFAULT_Light(15) text:@"" textColor:Label_Color] setupOnView:self];
    
    self.grayTitleL = [[[UILabel labelWithFrame:CGRectMake(self.titleL.right, self.titleL.top, grayTitleLW, self.titleL.height) font:FONT_DEFAULT_Light(12) text:@"" textColor:Label_Gray_Color] setupOnView:self]labelResetTextAlignment:NSTextAlignmentRight];
    
    self.detailL = [[UILabel labelWithFrame:CGRectMake(self.titleL.left, CELL_HEIGHT - titleLH - titleLY, detailLW, self.titleL.height) font:FONT_DEFAULT_Light(14) text:@"" textColor:Label_Detail_Color] setupOnView:self];
    
    [[[UIView viewWithFrame:CGRectMake(0, CELL_HEIGHT - 0.5, __MAIN_WIDTH, 0.5)] setupOnView:self] resetBackgroundColor:[Theme lineColor]];
    
}
- (void)reloadDataIcon:(NSString *)iconStr title:(NSString *)title model:(MessageCenterModel *)model
{
    [self.iconImageV setImage:ImageNamed(iconStr)];
    self.titleL.text = title;
    self.grayTitleL.text = model.newestMessage.dateTime;
    self.detailL.text = ([model.newestMessage.ABSTRACT isNotNil] ? model.newestMessage.ABSTRACT : @"暂时没有新消息哦～");
    NSString * messageCount = model.unread > 9 ? @"9+" :[NSString stringWithFormat:@"%zd",model.unread];
    [self.iconImageV showRemind:model.unread > 0 title:messageCount center:CGPointMake(self.iconImageV.width, 0)];
}
+ (CGFloat)getCellHeight
{
    return CELL_HEIGHT;
}
- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
